<template>
  <h1>你好 VUE3</h1>
  姓：<input type="text" v-model="person.firstName" /> <br /><br />
  名：<input type="text" v-model="person.lastName" /> <br /><br />
  全名：{{ person.fullName }} <br /><br />
  全名：<input type="text" v-model="person.fullName" />
</template>

<script>
import { reactive, computed } from "vue";
export default {
  name: "App",
  setup() {
    const person = reactive({
      firstName: "张",
      lastName: "三",
    });

    // 简写形式，不考虑修改
    // person.fullName = computed(() => {
    //   return person.firstName + person.lastName;
    // });

    // 完整形式，考虑修改
    person.fullName = computed({
      get() {
        return person.firstName + "-" + person.lastName;
      },
      set(value) {
        const [firstName, lastName] = value.split("-");
        person.firstName = firstName;
        person.lastName = lastName;
      },
    });
    return {
      person,
    };
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
